﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ServerCommon.Architecture
{
    public class CommandLineHelper
    {
        public static string GetOption(string[] args, int index, string defaultValue)
        {
            if (args is not { Length: > 0 })
            {
                return defaultValue;
            }
            return index >= args.Length ? defaultValue : args[index];
        }

        public static string GetOption(string[] args, string option, string defaultValue)
        {
            if (args is not { Length: > 0 } || string.IsNullOrEmpty(option))
            {
                return defaultValue;
            }
            var idx = Array.FindIndex(args, (p) => p == option);
            return idx < 0 ? defaultValue : GetOption(args, idx + 1, defaultValue);
        }
    }
}
